from django.conf import settings
from itsdangerous import TimedJSONWebSignatureSerializer

#创建加密对象
t = TimedJSONWebSignatureSerializer(settings.SECRET_KEY, 300)

#openid加密
def generate_sign_openid(openid):
    #返回加密后的openid
    return  t.dumps({"openid":openid}).decode()

#openid解密
def decode_sign_openid(sign_openid):
    #open解密，如何报错，说明为空
    try:
        dict_data=t.loads(sign_openid)
    except Exception as e:
        return None

    #返回数据
    return dict_data.get("openid")

